<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.text.SimpleDateFormat,java.util.Calendar"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	Calendar cal = Calendar.getInstance();
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	String today = format.format(cal.getTime());
%>
<!DOCTYPE HTML>
<html>
	<head>
		<base href="<%=basePath%>">
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link type="text/css" rel="stylesheet" href="include/css/welcome.css" />
		<link type="text/css" rel="stylesheet" href="include/css/css.css" />
		<link type="text/css" rel="stylesheet" href="include/css/bootstrap.css" />
		<link type="text/css" rel="stylesheet" href="include/css/bootstrap-datetimepicker.min.css" />
		<link type="text/css" rel="stylesheet" href="include/iconFont/1.0.8/iconfont.css"/ >
		<link type="text/css" rel="stylesheet" href="include/layer/skin/default/layer.css"/>
		<link rel="stylesheet" href="include/css/H-ui.css" type="text/css"/>
		<link rel="stylesheet" href="include/css/H-ui.admin.css" type="text/css"/>
		<link rel="stylesheet" href="include/icheck/icheck.css" type="text/css"/>
	</head>
	<script type="text/javascript">
		function init(){
			$('.form_datetime').datetimepicker({
		        format: 'yyyy-mm-dd hh:ii',
		        language: 'zh-CN',
		        pickDate: true,
		        pickTime: true,
		        hourStep: 1,
		        minuteStep: 15,
		        secondStep: 30,
		        autoclose: true,
		        pickerPosition: "bottom-left",
		        inputMask: true
		    });
			
			getAccountStates();
		}
		
		function getAccountStates()
		{
			var ddl = $("#accountType");
            $.ajax({
				type: "POST",
				data:{"statusType":"ACCOUNTTYPE"},
				url: "JqueryAction/getSetupState.action",
				dataType: "json",
				async:false,
				cache:false, 
				success: function(datas)
				{
            		document.getElementById("accountType").options.length=1;
					for(var i=0;i<datas.length;i++)
					{
						ddl.append("<option value="+datas[i].statusValue+">"+datas[i].statusName+"</option>");
					}
				}
			});
		}
		
		function submitAccount()
		{
			var accountType = $("#accountType")[0].value;
			var accountnum = $("#accountnum").val();
			var accounttime = $("#accounttime").val();
			var accountremark = $("#remark").val();
			
			if('' == accountType)
			{
				layer.tips('请选择一项账目类型', '#accountType', {
				  tips: [3, '#FF3300']
				});
				return;
			}
			
			if('' == accountnum)
			{
				layer.tips('请填写账目金额', '#accountnum', {
				  tips: [3, '#FF3300']
				});
				return;
			}
			else if(isNaN(accountnum))
			{
				layer.tips('请输入数字金额', '#accountnum', {
				  tips: [3, '#FF3300']
				});
				return;
			}
			
			layer.confirm('确定录入此账目吗？', {
				  btn: ['确定录入','取消录入'],skin: 'layui-layer-lan',shade: [0],closeBtn: false
				}, function(){
					$.ajax({
					type: "POST",
					url: "AccountAction/addAccount.action",
					dataType: "json",
					data:{"accountType":accountType,"accountnum":accountnum,"accounttime":accounttime,"remark":accountremark},
					success: function(res)
					{
						if(res.result)
						{
							parent.test('saveAccount');
								
	                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	                        parent.layer.close(index);
						}
						else
						{
							layer.msg('账目录入失败，请联系作者！', {icon: 2});
						}
					}
				});
				}, function(){
				  layer.msg('已取消', {icon: 2});
				});
		}
	</script>
	<body onload="init();">
		<article class="page-container">
		<form class="form form-horizontal" id="addform">
			<div class="row cl" id="cs2">
				<label class="form-label col-xs-3 col-sm-3">
					<span class="c-red">*</span>账目类型：
				</label>
				<div class="formControls col-xs-6 col-sm-9">
					<span class="select-box" style="width: 261px;height: 35px;"> 
						<select class="select" name="accountType" id="accountType">
							<option value="">--请选择--</option>
						</select> 
					</span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-3">
					<span class="c-red">*</span>账目金额：
				</label>
				<div class="input-group col-xs-7 col-sm-10">
					<input type="text" class="input-text" placeholder="请输入金额" name="accountnum" id="accountnum">
					<span class="input-group-btn">
						<button  class="btn btn-danger" type="button" style="height: 31px">元</button>
					</span> 
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-3">
					<span class="c-red">*</span>产生时间：
				</label>
				<div class="formControls col-xs-6 col-sm-9">
					<span class="select-box inline radius" style="width: 261px;"> 
						<input size="16" style="width: 240px;height: 25px;" type="text" 
								value="<%=today %>" readonly class="form_datetime form-control" 
																id="accounttime" name="accounttime"/>
					</span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-3">
					<span class="c-blue">*</span>账目备注：
				</label>
				<div class="formControls col-xs-7 col-sm-9">
					<input type="text" class="input-text" placeholder="请输入账目备注"
						id="remark" name="remark">
				</div>
			</div><br/>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="button" style="margin-left: 20px;"
						value="&nbsp;&nbsp;入 账&nbsp;&nbsp;" id="adds" onclick="submitAccount();">
				</div>
			</div>
		</form>
		<br/>
		</article>
		<hr>
		<script type="text/javascript" src="include/js/jquery-1.7.min.js"></script>
		<script type="text/javascript" src="include/js/bootstrap.js"></script>
		<script type="text/javascript" src="include/layer/layer.js"></script>
		<script type="text/javascript" src="include/js/bootstrap-datetimepicker.js"></script>
		<script type="text/javascript" src="include/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
	</body>
</html>